#pragma once
#include "GLTools.h"
#include <QWidget>

#if USE_QGL == 0
enum GLInitResult
{
	GL_INIT_FAILED = -1,
	GLEW_INIT_FAILED = -2,
	GL_OK = 0,
	GL_OK_MSAA = 1
};
class GLWidget : public QWidget
{
	Q_OBJECT

public:
	GLWidget(QWidget *parent);
	virtual ~GLWidget();

	void EnableVsync(bool enable);

	void GLUpdate();

protected:

	bool event(QEvent *event);

	virtual void showEvent(QShowEvent *event);

	virtual void resizeEvent(QResizeEvent *event);

	virtual void initializeGL();

	virtual	void resizeGL(int w, int h);

	virtual void paintGL();

private:
	GLInitResult CheckSupportGLLevel(int *major, int *minor);

	void* CreateGLRC(void* hdc, bool supportMSAA, int msaaLevel);

	bool SetupPixelFormat(void* hdc);

	virtual QPaintEngine* paintEngine() const { return NULL; }

	void Render();

	void MakeCurrentGLContext(bool use);

private:

	void* dc;
	void* rc;

	bool isInit = true;
	bool isChanged = false;
	int _width;
	int _height;
	int major = 0, minor = 0;
};
#endif